<?php 
namespace app\agent\controller;

use think\Controller;
use think\Request;
use app\common\model\user\Users;

class Login extends Controller
{
	/**
	 * 用户登录
	 * @param Request $request
	 * @return unknown
	 */
	public function index(Request $request)
	{
		if($request->isAjax()){
			$data = $request->post('');
			$data['password'] = md5($data['password']);
			$user = Users::where(['user_name' => $data['mobile'],'password' => $data['password']])->find();
			if(!$user){
				return $this->error('手机号码或者密码错误');
			}
			if(!$user['is_act'])return $this->error('无权限');
			session('agent_id',$user['id']);
			return $this->success('登陆成功');
		}
		return view();
	}
	
	public function outLogin()
	{
		session('agent_id',null);
		$this->error('退出登录',url("login/index"));
	}
}